package com.example.xiaomi.Model.Dao;

import com.example.xiaomi.Model.entity.addAddressEntity;
import com.example.xiaomi.Model.utils.BaseDB;
import com.example.xiaomi.Model.utils.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class addAddressDao extends BaseDB {

    public Integer doInsert(int aid,String amail,String aprovince,String acity,String adistrict,String astreet,String adetail,String label,String aname,String aphone){
        String sql="insert into is_address values(?,?,?,?,?,?,?,?,?,?)";
        return super.insert(sql,aid,amail,aprovince,acity,adistrict,astreet,adetail,label,aname,aphone);
    }
    public Integer doUpdate(int id,String amail,String aprovince,String acity,String adistrict,String astreet,String adetail,String label,String aname,String aphone){
        String sql="update is_address set amail=?,aprovince=?,acity=?,adistrict=?,astreet=?,adetail=?,label=?,aname=?,aphone=? where aid <=>"+id;
        return super.insert(sql,amail,aprovince,acity,adistrict,astreet,adetail,label,aname,aphone);
    }

    class AddressDaoRowMapper implements RowMapper<addAddressEntity> {
        @Override
        public addAddressEntity rowmap(ResultSet rs) throws SQLException {
            return new addAddressEntity(rs.getInt("aid"),
                                  rs.getString("amail"),
                                  rs.getString("aprovince"),
                                  rs.getString("acity"),
                                  rs.getString("adistrict"),
                                  rs.getString("astreet"),
                                  rs.getString("adetail"),
                                  rs.getString("label"),
                                  rs.getString("aname"),
                                  rs.getString("aphone")
            );
        }
    }

}
